// job.js
// CREATE TABLE IF NOT EXISTS jobs (
//     id INTEGER PRIMARY KEY AUTOINCREMENT,
//     input TEXT,
//     output TEXT DEFAULT '',
//     config TEXT DEFAULT '',
//     status TEXT DEFAULT 'pending',
//     current_node TEXT DEFAULT NULL,
//     current_task INTEGER DEFAULT NULL,
//     create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
//     update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
// )
class Job {
    constructor(id, config, input) {
        this.id = id;
        this.config = config;
        this.input = input;
        this.output = null;
        this.status = 'pending'; // pending, running, completed, failed
        this.error = null;
        this.current_node = null; // 当前正在执行的节点
        this.current_task = null; // 当前正在执行的任务
    }

    start() {
        this.status = 'running';
    }

    complete(output) {
        this.status = 'completed';
        this.output = output;
    }

    fail(error) {
        this.status = 'failed';
        this.error = error;
    }

    setCurrentNode(nodeName) {
        this.current_node = nodeName;
    }

    setCurrentTask(taskId) {
        this.current_task = taskId;
    }
}

module.exports = { Job };
